/**
 * Copyright(c)2013 Beijing PeaceMap Co.,Ltd.
 * All right reserved. 
 */
package com.pmc.dwa.common.utils.jhlabs;

import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.image.BufferedImage;
import java.awt.image.ColorModel;


/**
 * @description 
 * @author aokunsang
 * @date 2013-3-19
 */
public class PmcScaleFilter extends AbstractBufferedImageOp  {

	private int width;
	private int height;
	
	public PmcScaleFilter(int width,int height){
		this.width = width;
		this.height = height;
	}
	
	@Override
	public BufferedImage filter(BufferedImage src, BufferedImage dst) {
		if ( dst == null ) {
			ColorModel dstCM = src.getColorModel();
			dst = new BufferedImage(dstCM, dstCM.createCompatibleWritableRaster( width, height ), 
									dstCM.isAlphaPremultiplied(), null);
		}
		Image scaleImage = src.getScaledInstance(width, height,Image.SCALE_SMOOTH);
		Graphics2D g = dst.createGraphics();
		g.drawImage(scaleImage, 0, 0, width, height, null );
		g.dispose();

        return dst;
	}
	
	@Override
	public String toString() {
		return "Distort/Scale";
	}
}
